<template>
	<!-- 密码校验 -->
	<view class="cu-modal" :class="pwdDialog=='Modal'?'show':''">
		<view class="cu-dialog">
			<view class="cu-bar">
				<view class="content">密码校验</view>
				<view class="action text-white" @tap="hidePwd" style="font-size: 32rpx;">取消</view>
				<view class="action text-white" @tap="checkPwd" style="font-size: 32rpx;">确定</view>
			</view>
			<view class="padding-xl">
				<view class="input-text-voice-super">
					<text class="action text-white" style="font-size: 32rpx;">请输入密码</text>
					<input v-model="password" type="password" class="chat-input-style" placeholder="请输入密码" />
				</view>
				<view class="input-text-voice-super">
					<text class="action text-white" style="font-size: 32rpx;">中控IP地址</text>
					<input v-model="localIP" type="text" class="chat-input-style" placeholder="请输入IP地址" />
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		props:{
			localServerIP:{
				type:String
			}
		},
		data(){
			return{
				pwdDialog:'',
				password:'',
				localIP:'',
			}
		},
		watch:{
			pwdDialog(type){
				console.log(this.localServerIP,'localServerIP')
				this.localIP = this.localServerIP;
			},
			localServerIP(val){
				console.log(val,'localServerIP')
				this.localIP = val;
			}
		},
		onShow() {
			
		},
		created() {
			
		},
		mounted() {
			
		},
		methods:{
			checkPwd() { //校验密码
			
				if(this.password == ''){
					uni.showToast({
						title:'请输入密码～',
						icon:'none'
					})
					
					return false;
				}
				
				if(this.localIP == ''){
					uni.showToast({
						title:'请输入IP地址',
						icon:'none'
					})
					
					return false;
				}
				
				if (this.localIP && !(
						/((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))/).test(this.localIP)) {
					uni.showToast({
						title: 'IP地址不规范～',
						icon: 'none'
					})
					return false;
				}
			
				if (this.password == 'szhssj') {
					uni.setStorageSync('zkLocalIP',this.localIP)
					uni.navigateTo({
						url: '/pages/deviceControl/index'
					})
					this.pwdDialog = '';
					this.localIP = '';
					this.password = '';
				} else {
					uni.showToast({
						title: '密码错误,请重新输入...',
						icon: 'none'
					})
				}
			},
			hidePwd() { //隐藏密码弹窗
				this.password = '';
				this.pwdDialog = '';
			},
		}
	}
</script>

<style scoped>
	@import "../../colorui/main.css";
	@import "../../colorui/icon.css";
	
	.cu-dialog {
		color: #fff;
		background-color: #535178;
	}
	.cu-bar {
		border-bottom: 1px solid #ccc;
	}
	.input-text-voice-super {
		display: flex;
		flex-direction: row;
		width: 100%;
		align-items: center;
		z-index: 20;
		margin-bottom: 5px;
	}
	
	.chat-input-style {
		border-radius: 20rpx;
		border: 1rpx solid #fff;
		margin-top: 14rpx;
		margin-bottom: 13rpx;
		padding: 10rpx 20rpx;
		min-height: 85rpx;
		color: #ffffff;
		margin-left: 10rpx;
		width: 75%;
		font-size: 32rpx;
	}
</style>
